//连接数据库
var db = openDatabase('mydb', '1.0', 'WJN_DB', 2 * 1024 * 1024);
//var msg;

//db.transaction(function(tx) {
////	tx.executeSql('DROP TABLE t_user');
//	tx.executeSql('CREATE TABLE IF NOT EXISTS t_user(id unique, name,password,role,img,addr,phone,realname)');
//	tx.executeSql('INSERT INTO t_user (id,name,password,role,img) VALUES (1,"admin","admin",0,"img/tx1.jpg")');
//	tx.executeSql('INSERT INTO t_user (id,name,password,role,img,addr,phone,realname) VALUES (2,"canan","123456",1,"img/tx2.jpg","广东省东莞市文昌路1号","15625521234","魏迦南")');
//	tx.executeSql('INSERT INTO t_user (id,name,password,role,img,addr,phone,realname) VALUES (3,"weijianan","123456",1,"img/tx3.jpg","广东省汕尾市华侨区","15625523456","魏迦南")');
//
//});

//db.transaction(function(tx) {
//	tx.executeSql("SELECT * FROM t_user where role = 1 and name='canan' and password='123456'", [], function(tx, results) {
//
//	}, null);
//});
function login(name, password) {
	db.transaction(function(tx) {
		tx.executeSql("SELECT * FROM t_user where role = 1 and name='" + name + "' and password='" + password + "'", [], function(tx, results) {
			if(results.rows.length > 0) {
				// 登录成功，以json形式将用户信息保存到SessionStorage
				var user = {
					id: results.rows.item(0).id,
					name: results.rows.item(0).name,
					password: results.rows.item(0).password,
					img: results.rows.item(0).img,
					addr : results.rows.item(0).addr,
					phone : results.rows.item(0).phone,
					realname : results.rows.item(0).realname
				}
				// 存储值：将对象转换为Json字符串
				sessionStorage.setItem('user', JSON.stringify(user));
				window.location.href = "index.html#pageFour";
			} else {
				alert("帐号或密码有误！");
			}
		}, null);
	});
}